<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="public/css.css"> 
<h1>ha Van Tan</h1>
<?php
require_once './model/db.php';

$query = "SELECT * FROM pages LIMIT 10;";
$pages = getFilms($query);
$keyword = NULL;
$ratingMin = NULL;
$ratingMax = NULL;
?>

<form method="POST">
    Keyword  : <input type="text" name="keyword"><br>
    Min fans &nbsp;: <input type="text" name="ratingMin"><br>
    Max fans : <input type="text" name="ratingMax"><br>
    <input type="submit" name="submit" value="Search">
</form>
<?php if (isset($_POST['submit'])): ?>
    <?php $keyword = (double) $_POST['keyword']; ?>
    <?php $ratingMin = (double) $_POST['ratingMin']; ?>
    <?php $ratingMax = (double) $_POST['ratingMax']; ?>
<?php endif; ?>

<table id="table" border="1px">
    <tr class="khung">
        <td class="pid">STT </td>
        <td class="id">id </td>
        <td class="name">Name </td>
        <td class="likes">Likes </td>
        <td class="talking">Talking</td>
        <td class="category">Category </td>
        <td class="link">Link </td>
        <td class="website">Website </td>
        <td class="picture">Picture </td>
        <td class="country">Country </td>
    </tr>
    <?php foreach ($pages as $page): ?>
        <?php if (empty($keyword) && empty($ratingMin) && empty($ratingMax)): ?>
            <tr>
                <td><?php echo $page["pid"] ?></td>
                <td><?php echo $page["id"] ?></td>
                <td><?php echo $page["name"] ?></td>
                <td><?php echo $page["likes"] ?></td>
                <td><?php echo $page["talking_about_count"] ?></td>
                <td><?php echo $page["category"] ?></td>
                <td><a href='<?php echo $page["link"] ?>'><?php echo $page["link"] ?></td>
                <td><a href='<?php echo $page["website"] ?>'><?php echo $page["website"] ?></td>
                <td><img src ='<?php echo $page["picture"] ?>'</td>
                <td><?php echo $page["country"] ?></td>
            </tr>
        <?php elseif (empty($keyword) && empty($ratingMax)): ?>
            <?php if ($ratingMin <= (double) $page["likes"]): ?>
                <tr>
                    <td><?php echo $page["pid"] ?></td>
                    <td><?php echo $page["id"] ?></td>
                    <td><?php echo $page["name"] ?></td>
                    <td><?php echo $page["likes"] ?></td>
                    <td><?php echo $page["talking_about_count"] ?></td>
                    <td><?php echo $page["category"] ?></td>
                    <td><a href='<?php echo $page["link"] ?>'><?php echo $page["link"] ?></td>
                    <td><a href='<?php echo $page["website"] ?>'><?php echo $page["website"] ?></td>
                    <td><img src ='<?php echo $page["picture"] ?>'</td>
                    <td><?php echo $page["country"] ?></td>
                </tr>
            <?php endif; ?>
        <?php else: ?>
            <?php if (($ratingMin <= (double) $page["likes"]) && ($ratingMax >= $page["likes"])): ?>
                <tr>
                    <td><?php echo $page["pid"] ?></td>
                    <td><?php echo $page["id"] ?></td>
                    <td><?php echo $page["name"] ?></td>
                    <td><?php echo $page["likes"] ?></td>
                    <td><?php echo $page["talking_about_count"] ?></td>
                    <td><?php echo $page["category"] ?></td>
                    <td><a href='<?php echo $page["link"] ?>'><?php echo $page["link"] ?></td>
                    <td><a href='<?php echo $page["website"] ?>'><?php echo $page["website"] ?></td>
                    <td><img src ='<?php echo $page["picture"] ?>'</td>
                    <td><?php echo $page["country"] ?></td>
                </tr>
            <?php endif; ?>
        <?php endif; ?>
    <?php endforeach; ?>
</table>